package com.demo.service.impl;

import com.demo.entity.*;
import com.demo.repository.GradeRepository;
import com.demo.repository.Sg;
import com.demo.repository.StudentRepository;
import com.demo.repository.TeacherRepository;
import com.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    TeacherRepository teacherRepository;
    @Autowired
    GradeRepository gradeRepository;
    @Autowired
    Sg sg;

    @Override
    public Teacher Login(String teacherName, String pawword) {
        TeacherExample teacherExample=new TeacherExample();
        teacherExample.createCriteria().andTeacherNameEqualTo(teacherName)
                .andPasswordEqualTo(pawword);
        List<Teacher> teachers = teacherRepository.selectByExample(teacherExample);
        if(teachers.isEmpty()){
            return null;
        }
        return teachers.get(0);
    }

    @Override
    public List<StudentGrade> teacherSelect(String subjectName) {

        List<StudentGrade> studentgrade = gradeRepository.SouSuo(subjectName);
        return studentgrade;
    }



    @Override
    public List<StudentGrade> souSuo(Integer classId,Integer season,String stuName,String subjectName) {
        return sg.selectAll(classId,season,stuName,subjectName);
    }

    @Override
    public void insertGrade(Grade grade) {
        gradeRepository.insertSelective(grade);
    }


}
